package com.example.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.domain.Dish;
import com.example.dto.DishDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishDao extends BaseMapper<Dish> {
    @Select("select count(*) from dish where category_id=#{id}")
    public int selectByCategoryId(Long id);

    @Select("select * from dish where category_id=#{id} and status=1")
    public List<Dish> selectbycactegoryid(Long id);

    @Select("select * from dish limit #{pageCount},#{pageSize}")
    public List<Dish> selectall(int pageCount,int pageSize);

    @Select("select count(*) from dish")
    public int selectcount();

    @Select("select * from dish where name=#{name}")
    public List<Dish> selectbyname(int pageCount,int pageSize,String name);

    @Insert("insert into dish values (#{id},#{name},#{categoryId},#{price},#{code},#{image},#{description},#{status},0,#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    public void save(DishDto dishDto);

    @Update("update dish set name=#{name},category_id=#{categoryId},price=#{price},image=#{image},description=#{description},update_time=#{updateTime},update_user=#{updateUser} where id=#{id}")
    public void update(DishDto dishDto);
    @Select("select * from dish where id=#{id}")
    public Dish selectbyid(Long id);

    @Update("update dish set status=#{status},update_time=#{updateTime},update_user=#{updateUser} where id=#{id}")
    public void dishStatusByStatus(Dish dish);

    @Delete("delete from dish where id=#{id}")
    public void deleteDish(Long id);

    @Select("select * from dish where category_id=#{categoryId} and status=#{status}")
    public List<Dish> selectbycategoryidandstatus(Dish dish);
}
